<template>
  <div class="memeory-bg">
    <Header :isTransBg="true" :width="1000" :isGoBack="false">
      <template v-slot:left>
        <span class="weight-title">
          {{ checkedBookData.edition_name }}-{{ checkedBookData.grade_name }}
        </span>
      </template>
      <template v-slot:right>
        <div
          class="help-btn mr10"
          @click="memoryHelpDialog = true"
          v-if="!isIintensiveWord"
        >
          <img
            class="ml5"
            slot="reference"
            src="@/assets/img/icon/help-normal.png"
            alt=""
          />
        </div>
        <div class="close-memeory" @click="goStudyCenter">
          关闭
          <img class="ml5" src="@/assets/img/close-circle.png" alt="" />
        </div>
      </template>
    </Header>

    <div class="memory-container w1000">
      <div class="memory-contain">
        <div
          style="display:flex;
          justify-content: space-between;
            align-items: center;"
        >
          <div
            class="historyWordList"
            v-if="historyWordList.length && historyWordListFlag"
          >
            <el-tag
              v-for="item in historyWordList"
              :key="item.id"
              type="warning"
              effect="dark"
            >
              {{ item.name }}
            </el-tag>
          </div>
          <div v-else></div>
          <el-tag
            @click="goTrace"
            type="warning"
            style="margin: 0.02604167rem;cursor: pointer;"
            effect="dark"
          >
            记忆追踪
          </el-tag>
        </div>

        <div class="memory-question">
          <div>
            <div class="memory-header">
              智能记忆-{{ isIintensiveWord ? "词义强化" : "词义记忆" }}
              <span class="fr reminder-text">
                <span v-if="isIintensiveWord && intensiveWord.word_id" class="">
                  <span v-if="isIintensiveWord">四个选项快捷键为1/2/3/4,</span>
                  按"Enter"进入下一题
                </span>
                <span class="feedback-btn ml10 click" @click="showFeedBack">
                  反馈
                </span>
              </span>
            </div>
            <!-- 单词测试组件 -->
            <StudyWord
              v-if="!isIintensiveWord && wordData.word_id"
              :wordData="wordData"
              @nextWord="nextWord"
              @checkFalseFun="checkFalseFun"
              @closeTimer="closeTimer"
              ref="studyWord"
            ></StudyWord>
            <TestQuestion
              v-if="isIintensiveWord && intensiveWord.word_id && isShowCom"
              :question="intensiveWord.question"
              @changeStudentAnswer="changeStudentAnswer"
              :isQuick="true"
              ref="testQuestion"
              :isMemory="true"
            >
            </TestQuestion>
            <div
              v-if="isIintensiveWord && intensiveWord.word_id && isShowCom"
              class="next-btn-container"
            >
              <el-button
                class="button button-bg-primary"
                @click="nextIntQuestion"
                :disabled="
                  intensiveWord.question &&
                    intensiveWord.question.is_true !== 1 &&
                    intensiveWord.question.is_true !== 0
                "
                >下一题</el-button
              >
            </div>
            <!-- <StudyQuestion
              v-if="isIintensiveWord && intensiveWord.word_id"
              :wordData="intensiveWord"
              @nextWord="nextIntensiveWord"
              @checkTrueFun="checkTrueFun"
              :isOpenMessageBox="isOpenMessageBox"
              ref="studyQuestion"
            ></StudyQuestion> -->
          </div>
        </div>
        <div v-if="!isIintensiveWord && wordData.word_id">
          <span>
            <!-- 倒计时：{{ countTimerNum }} -->
          </span>

          <span>
            本次学习：生词：{{ newWordNum }} 熟词：{{ skilledNum }} 本次复习：{{
              reviewNum
            }}
          </span>
        </div>
        <div v-if="isIintensiveWord && intensiveWord.word_id">
          <span></span>
          <span>
            进度：{{ intensiveWordIndex + 1 }} / {{ intensiveWordList.length }}
          </span>
        </div>
      </div>
    </div>
    <el-dialog
      title="帮助"
      :visible.sync="memoryHelpDialog"
      width="800px"
      class="memory-help"
    >
      <div>
        <div>
          <div class="mb30">
            <img src="../../../assets/img/step-study-2.png" alt="" />
          </div>
          <div class="mb10">
            <img src="../../../assets/img/step-study-1.png" alt="" />
          </div>
          <el-divider></el-divider>
          <div></div>
        </div>
        <div>
          <div class="key-point">
            <label>
              <span class="line"></span>
              <span>关键点:</span>
            </label>
            <div>
              <p class="point-info">点击认识或不认识一定要真实;</p>
              <p class="point-info">
                跟读时，
                <span class="red-color-text">单词+词义</span
                >一定要连起来，读出声;
              </p>
              <p class="point-info">
                认识的单词读<span class="red-color-text">一遍英文+一遍中文</span
                >；
              </p>
              <p class="point-info">
                不认识的单词读两轮，每一轮读<span class="red-color-text"
                  >四遍英文+一遍中文</span
                >；
              </p>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
    <Feedback
      ref="feedback"
      :type="1"
      :classify="1"
      @openDialog="isOpenMessageBox = true"
      @closeDialog="isOpenMessageBox = false"
    ></Feedback>
    <!-- 词义强化 -->
    <el-dialog
      title="提示"
      :visible.sync="isSkipIntensiveWord"
      width="30%"
      :before-close="handleClose"
    >
      <span>请点击是否跳过词义强化</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="SkipIntensiveWord(0)">不跳过</el-button>
        <el-button type="primary" @click="SkipIntensiveWord(1)">跳过</el-button>
      </span>
    </el-dialog>
    <ReviewDialog :toRouter="toRouter" :reviewFlag="reviewFlag" :reviewData="reviewData" :intensiveWordList="intensiveWordList"></ReviewDialog>
  </div>
</template>
<script>
import Header from "@/components/Header";
import StudyWord from "../components/StudyWord";
import ReviewDialog from '@/components/ReviewDialog';
import TestQuestion from "../components/TestQuestion";
import { getWordQuestions } from "@/api/index";
import Feedback from "@/components/Feedback";
import { throttle } from "@/utils/utils";
import EventBus from "@/assets/js/eventBus";
import {
  experiencefindWordPronunciationVo,
  experienceEstimateWord,
  experienceCreate,
  experienceWordExercise,
  experienceWordReviewSearch,
  experiencePass,
  // 隔断
  getStudyWordList,
  setEstimateWord,
  setWordExercise,
  getMemoryReview,
  setWordPass,
  addIntegral,
  getReviewNumber,
  setIsForce,
  skipWordGroupRecord,
} from "@/api/index";
import {
  findWordPronunciationVo,
  updateWordStatus,
  createInvidualizedWord,
  wordExercise,
  wordSearch,
  pass,
} from "@/api/individuationRead.js";
import { formatDate } from "@/utils/dateUtil";

export default {
  data() {
    return {
      toRouter: null,
      reviewTitle: formatDate(new Date(), "yyyy-MM-dd") + " 复习报告",
      reviewFlag: false,
      reviewData: [],
      historyWordListFlag: true,
      historyWordList: [],
      tagGroupId: null,
      wordList: [],
      wordData: {},
      checkedWordIndex: -1,
      intensiveWordList: [],
      intensiveWordIndex: -1,
      isIintensiveWord: false,
      intensiveWord: {},
      groupData: {},
      initSkilledNum: 0,
      initReviewNum: 0,
      initNewWordNum: 0,
      countTimer: null,
      countTimerNum: 5,
      unitId: null,
      category: 0,
      checkedBookData: null,
      addIntegralNum: 0,
      memoryHelpDialog: false,
      isOpenMessageBox: false,
      isShowCom: true,
      isForce: 0,
      review_number: 0,
      testId: 1,
      isSkipIntensiveWord: false,
    };
  },
  computed: {
    skilledNum() {
      let data = this.wordList.filter((item) => {
        return !item.isReview && item.checkAnswer === true;
      });
      return data.length + this.initSkilledNum;
    },
    reviewNum() {
      let data = this.wordList.filter((item) => {
        return (
          item.isReview &&
          (item.checkAnswer === true || item.checkAnswer === false)
        );
      });
      return data.length + this.initReviewNum;
    },
    newWordNum() {
      let data = this.wordList.filter((item) => {
        return !item.isReview && item.checkAnswer === false;
      });
      return data.length + this.initNewWordNum;
    },
  },
  beforeRouteLeave(to, from, next) {
    console.log(to,"sdfad");
    this.toRouter = to;
    if (this.reviewFlag == true||!this.$route.query.isReview) {
      next();
    }else{
      this.reviewFlag = true
    }
  },
  watch: {
    "intensiveWord.question": {
      handler(newVal, oldVal) {
        this.historyWordListFlag = false;
      },
      deep: true,
    },
    wordData: {
      handler(newVal, oldVal) {
        this.historyWordListFlag = true;
        const { name, id } = oldVal;
        if (name == undefined || id == undefined) return;
        this.historyWordList = this.historyWordList.filter(
          (item) => item.id != id
        );
        if (this.historyWordList.length >= 5) {
          this.historyWordList = this.historyWordList.slice(-4);
        }
        this.historyWordList.push({ name, id });
        console.log(this.historyWordList, "this.historyWordList");
        console.log(newVal, oldVal, "test1111");
      },
      deep: true,
    },
  },
  components: {
    ReviewDialog,
    StudyWord,
    // StudyQuestion,
    Header,
    Feedback,
    TestQuestion,
  },
  methods: {
    goTrace() {
      this.$router.push({
        name: "memoryReview",
        query: {
          ...this.$route.query,
          isReturn: true,
        },
      });
    },
    handleClose() {
      this.isSkipIntensiveWord = false;
      this.SkipIntensiveWord(0);
    },
    // 跳过词义强化 10.16日期
    async SkipIntensiveWord(id) {
      this.testId = id;
      this.isIintensiveWord = true;
      this.isSkipIntensiveWord = false;
      if (this.testId == 1) {
        //点击跳过 或者后台是强制跳过的时候
        //执行新接口  这样就可以获取到下一组数据
        let params = {
          groupId: this.groupData.group_id,
        };
        await skipWordGroupRecord(params);
      }
      this.getStudyData();
    },
    setIsForce() {
      setIsForce(this.checkedBookData.book_id).then((res) => {
        console.log(res);
      });
    },
    cancelForce() {
      this.isForce = 0;
      this.setIsForce();
    },
    setInitWordNum() {
      let data1 = this.wordList.filter((item) => {
        return !item.isReview && item.checkAnswer === true;
      });
      let data2 = this.wordList.filter((item) => {
        return (
          item.isReview &&
          (item.checkAnswer === true || item.checkAnswer === false)
        );
      });
      let data3 = this.wordList.filter((item) => {
        return !item.isReview && item.checkAnswer === false;
      });
      this.initSkilledNum += data1.length;
      this.initReviewNum += data2.length;
      this.initNewWordNum += data3.length;
    },
    nextIntQuestion() {
      console.log(this.intensiveWord, "intensiveWord");
      if (this.intensiveWord.question.is_true == 1) {
        this.nextIntensiveWord();
      } else {
        this.changeQuestion();
      }
    },
    changeStudentAnswer(studentAnswer) {
      let is_true = 0;
      console.log(this.intensiveWord.question);
      if (studentAnswer == this.intensiveWord.question.trueAnswer) {
        is_true = 1;
      }
      if (this.$route.query.isReview) {
        if (
          !this.reviewData.filter(
            (item) => item.word_id == this.intensiveWord.question.word_id
          ).length
        ) {
          this.reviewData.push({
            word_id: this.intensiveWord.question.word_id,
            is_true,
          });
        }
      }
      let question = Object.assign(this.intensiveWord.question, {
        is_true,
        studentAnswer,
        isChecked: true,
      });
      this.changeQuestion(question);
      this.checkTrueFun(is_true);
    },
    changeQuestion(question) {
      let isInitQuestion = !question;
      if (!question) {
        question = Object.assign(this.intensiveWord.question, {
          is_true: null,
          studentAnswer: "",
          isChecked: false,
        });
      }
      this.isShowCom = false;
      this.$set(this.intensiveWord, "question", question);
      this.$nextTick(() => {
        this.isShowCom = true;
        this.$nextTick(() => {
          if (isInitQuestion && this.$refs.testQuestion) {
            this.$refs.testQuestion.playAudio("audioPlay");
          }
          2;
        });
      });
    },
    showFeedBack() {
      let id = this.isIintensiveWord
        ? this.intensiveWord.word_id
        : this.wordData.word_id;
      if (id) {
        this.$refs.feedback.visible(id);
      }
    },
    //  需要复习的单词两个之后插一个，标记isReview:true
    nextWord: function() {
      if (this.wordList.length <= 0) {
        return;
      }
      //
      if (
        this.checkedWordIndex < this.wordList.length - 1 &&
        this.wordList.length > 0
      ) {
        this.checkedWordIndex++;
        this.setWordData(this.wordList[this.checkedWordIndex]);
      } else {
        this.getStudyData();
      }
    },
    nextIntensiveWord: throttle(function() {
      if (this.intensiveWordList.length <= 0) {
        return;
      }
      if (
        this.intensiveWordIndex < this.intensiveWordList.length - 1 &&
        this.intensiveWordList.length > 0
      ) {
        this.intensiveWordIndex++;
        this.setIntensiveWordData(
          this.intensiveWordList[this.intensiveWordIndex]
        );
      } else {
        this.getStudyData();
      }
    }, 300),
    setIntensiveWordData(data) {
      this.intensiveWord = data;
      this.intensiveWord.startTime = new Date().getTime();
      this.$nextTick(() => {
        if (this.$refs.testQuestion) {
          this.$refs.testQuestion.playAudio("audioPlay");
        }
      });
    },
    setWordData(data) {
      this.wordData = data;
      this.wordData.startTime = new Date().getTime();
      // this.setCountTimer();
      this.$nextTick(() => {
        if (this.$refs.studyWord) {
          this.$refs.studyWord.playAudio("audioPlay");
        }
      });
    },
    setEstimateWord(not) {
      return new Promise((reslove, reject) => {
        if (this.$route.query.title == "体验生词库") {
          if (this.wordData.isReview) {
            Promise.resolve(
              reslove({ code: 200, data: 1, message: "操作成功" })
            );
            return;
          }
          let data = {
            source: 4,
            not: not,
            bookId: 600,
            number: this.checkedBookData.number,
            unitId: this.unitId,
            wordId: this.wordData.word_id,
            groupId: this.groupData.group_id,
            category: 4,
            useTime: parseInt(
              (this.wordData.endTime - this.wordData.startTime) / 1000
            ),
            wid: this.wordData.wid,
            isStrange: this.wordData.isReview ? 1 : 0,
          };
          experienceEstimateWord(data)
            .then((res) => {
              reslove(res);
            })
            .catch((error) => {
              reject(error);
            });
          return;
        }
        if (this.$route.query.title == "单词库") {
          if (this.wordData.isReview) {
            Promise.resolve(
              reslove({ code: 200, data: 1, message: "操作成功" })
            );
            return;
          }
          let data = {
            gradeId: this.$route.query.unitId,
            wordId: this.wordData.word_id,
            state: not ? 1 : 0,
            groupId: this.$route.query.groupId,
          };
          updateWordStatus(data)
            .then((res) => {
              reslove(res);
            })
            .catch((error) => {
              reject(error);
            });
          return;
        }
        let data = {
          not: not,
          bookId: this.checkedBookData.book_id,
          number: this.checkedBookData.number,
          unitId: this.unitId,
          wordId: this.wordData.word_id,
          groupId: this.groupData.group_id,
          category: this.category,
          useTime: parseInt(
            (this.wordData.endTime - this.wordData.startTime) / 1000
          ),
          wid: this.wordData.wid,
          isStrange: this.wordData.isReview ? 1 : 0,
        };
        setEstimateWord(data)
          .then((res) => {
            reslove(res);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    setWordPass(not) {
      return new Promise((reslove, reject) => {
        if (
          not ||
          this.$route.query.title == "单词库" ||
          this.$route.query.title == "体验生词库"
        ) {
          let num = this.intensiveWord.wrongNum;
          // let data = {
          //   category: this.category,
          //   book_id: this.checkedBookData.book_id,
          //   word_id: this.intensiveWord.word_id,
          //   memory_strength: 30 - num * 10 < 0 ? 0 : 30 - num * 10,
          // };
          // console.log(data);
          if (this.$route.query.title == "体验生词库") {
            let data = {
              library_id: this.intensiveWord.lid,
              category: 4,
              book_id: 600,
              word_id: this.intensiveWord.word_id,
              memory_strength: 30 - num * 10 < 0 ? 0 : 30 - num * 10,
              pass: not,
            };
            experiencePass(data)
              .then((res) => {
                if (res.code == 200) {
                  this.review_number++;
                  if (this.isForce && this.review_number >= 40) {
                    this.cancelForce();
                  }
                }
                reslove(res);
              })
              .catch((error) => {
                reject(error);
              });
          } else if (this.$route.query.title == "单词库") {
            let data = {
              library_id: this.intensiveWord.lid,
              category: this.category,
              book_id: this.checkedBookData.book_id,
              word_id: this.intensiveWord.word_id,
              memory_strength: 30 - num * 10 < 0 ? 0 : 30 - num * 10,
              pass: not,
            };
            pass(data)
              .then((res) => {
                if (res.code == 200) {
                  this.review_number++;
                  if (this.isForce && this.review_number >= 40) {
                    this.cancelForce();
                  }
                }
                reslove(res);
              })
              .catch((error) => {
                reject(error);
              });
          } else {
            let data = {
              category: this.category,
              book_id: this.checkedBookData.book_id,
              word_id: this.intensiveWord.word_id,
              memory_strength: 30 - num * 10 < 0 ? 0 : 30 - num * 10,
            };
            setWordPass(data)
              .then((res) => {
                if (res.code == 200) {
                  this.review_number++;
                  if (this.isForce && this.review_number >= 40) {
                    this.cancelForce();
                  }
                }
                reslove(res);
              })
              .catch((error) => {
                reject(error);
              });
          }
        }
      });
    },

    setWordExercise(not) {
      let useTime = 0;
      if (this.intensiveWord.endTime && this.intensiveWord.startTime) {
        useTime = parseInt(
          (this.intensiveWord.endTime - this.intensiveWord.startTime) / 1000
        );
      }
      if (this.intensiveWord.initUseTime) {
        useTime += this.intensiveWord.initUseTime;
      }
      return new Promise((reslove, reject) => {
        let data = {
          groupId:
            this.$route.query.title == "单词库" && this.tagGroupId
              ? this.tagGroupId
              : this.groupData.group_id,
          wid: this.intensiveWord.wid,
          wordId: this.intensiveWord.word_id,
          number: this.checkedBookData.number,
          not: not,
          bookId: this.checkedBookData.book_id,
          unitId: this.unitId,
          useTime: useTime,
          source: this.category,
        };
        if (this.$route.query.title == "体验生词库") {
          data.bookId = 600;
          data.source = 4;
          experienceWordExercise(data)
            .then((res) => {
              reslove(res);
            })
            .catch((error) => {
              reject(error);
            });
        } else if (this.$route.query.title == "单词库") {
          wordExercise(data)
            .then((res) => {
              reslove(res);
            })
            .catch((error) => {
              reject(error);
            });
        } else {
          setWordExercise(data)
            .then((res) => {
              reslove(res);
            })
            .catch((error) => {
              reject(error);
            });
        }
      });
    },
    //词义记忆选择认不认识
    async checkFalseFun(data, fun) {
      this.wordData.endTime = new Date().getTime();
      this.closeTimer();
      if (this.isReview) {
        await this.setWordPass(data);
      } else {
        await this.setEstimateWord(data);
      }
      // this.wordData.checkAnswer = data;
      this.$set(this.wordData, "checkAnswer", data);
      if (!data) {
        if (this.checkedWordIndex + 3 < this.wordList.length) {
          this.wordList.splice(
            this.checkedWordIndex + 3,
            0,
            Object.assign({}, this.wordData, {
              isReview: true,
              checkAnswer: null,
            })
          );
          //
        } else {
          this.wordList.push(
            Object.assign({}, this.wordData, {
              isReview: true,
              checkAnswer: null,
            })
          );
        }
      }
      if (fun) {
        fun();
      }
    },
    // 词义强化答对
    async checkTrueFun(not) {
      this.intensiveWord.endTime = new Date().getTime();
      if (not || (this.$route.query.title == "单词库" && this.isReview)) {
        //答对了
        if (this.isReview) {
          await this.setWordPass(not);
        } else {
          //判断第一次正确还是错误
          if (
            this.intensiveWord.firstIsTrue !== true &&
            this.intensiveWord.firstIsTrue !== false
          ) {
            this.intensiveWord.firstIsTrue = !this.intensiveWord.wrongNum > 0;
          }
          if (
            this.intensiveWord.firstIsTrue === true &&
            this.intensiveWord.num >= 1
          ) {
            await this.setWordExercise(not);
          } else if (
            this.intensiveWord.firstIsTrue === false &&
            this.intensiveWord.num >= 2
          ) {
            await this.setWordExercise(not);
          } else {
            let initUseTime = 0;
            if (this.intensiveWord.endTime && this.intensiveWord.startTime) {
              initUseTime = parseInt(
                (this.intensiveWord.endTime - this.intensiveWord.startTime) /
                  1000
              );
            }
            if (this.intensiveWord.initUseTime) {
              initUseTime += this.intensiveWord.initUseTime;
            }
            let wordData = Object.assign({}, this.intensiveWord, {
              isReview: true,
              wrongNum: 0,
              num: this.intensiveWord.num + 1,
              initUseTime,
            });
            this.insertIntensiveWord(wordData);
          }
        }
      } else {
        // 答错了
        this.intensiveWord.wrongNum++;
        if (
          this.$route.query.title == "体验生词库" &&
          this.$route.query.isReview != "true"
        ) {
          let data = {
            // groupId: this.tagGroupId ? this.tagGroupId : 0,
            wid: this.intensiveWord.wid,
            wordId: this.intensiveWord.word_id,
            number: this.checkedBookData.number,
            not: false,
            bookId: 600,
            unitId: this.unitId,
            useTime: 5,
            source: 4,
          };
          experienceWordExercise(data).catch((error) => {
            this.$message.error(`${error}`);
          });
        } else if (
          this.$route.query.title == "单词库" &&
          this.$route.query.isReview != "true"
        ) {
          let data = {
            groupId: this.tagGroupId ? this.tagGroupId : 0,
            wid: this.intensiveWord.wid,
            wordId: this.intensiveWord.word_id,
            number: this.checkedBookData.number,
            not: false,
            bookId: this.checkedBookData.book_id,
            unitId: this.unitId,
            useTime: 5,
            source: this.category,
          };
          wordExercise(data).catch((error) => {
            this.$message.error(`${error}`);
          });
        }
      }
    },
    // 词义强化隔两个插入
    insertIntensiveWord(wordData) {
      let data;
      if (this.$route.query.title == "体验生词库") {
        data = {
          book_id: 600,
          question_type: 1,
          source: 4,
          unit_id_list: [this.unitId],
          word_id_list: [wordData.word_id],
        };
      } else if (this.$route.query.title == "单词库") {
        data = {
          book_id: this.checkedBookData.book_id,
          question_type: 1,
          source: 0,
          // unit_id_list: [this.unitId],
          grade_id: Number(this.unitId),
          word_id_list: [wordData.word_id],
        };
      } else {
        // 获取词义强化的题目
        data = {
          book_id: this.checkedBookData.book_id,
          question_type: 1,
          source: this.category,
          unit_id_list: [this.unitId],
          word_id_list: [wordData.word_id],
        };
      }
      if (this.$route.query.title == "体验生词库") {
        experienceCreate(data).then((res) => {
          this.disposeWordQuestions(res, wordData);
        });
      } else if (this.$route.query.title == "单词库") {
        createInvidualizedWord(data).then((res) => {
          this.disposeWordQuestions(res, wordData);
        });
      } else {
        getWordQuestions(data).then((res) => {
          this.disposeWordQuestions(res, wordData);
        });
      }
    },
    // 处理单词问题
    disposeWordQuestions(res, wordData) {
      if (res.code == 200 && res.data) {
        let question = res.data[0];
        question.studentAnswer = "";
        question.isChecked = false;
        question.trueAnswer = "";
        question.audioURL = wordData.audioURL;
        let answerData = question.answer_list.filter((item) => {
          if (item.is_true && item.is_true == 1) {
            return true;
          } else {
            return false;
          }
        });
        if (answerData.length > 0) {
          question.trueAnswer = answerData[0].paraphrase;
        }
        wordData.question = question;
        if (this.intensiveWordIndex + 3 < this.intensiveWordList.length) {
          this.intensiveWordList.splice(
            this.intensiveWordIndex + 3,
            0,
            wordData
          );
        } else {
          this.intensiveWordList.push(wordData);
        }
      }
    },
    // 返回单词中心
    goStudyCenter() {
      if (this.$route.query.title == "体验生词库") {
        this.$router.push({
          name: "experientialStudyCenter",
        });
        return;
      }
      if (this.$route.query.title == "单词库") {
        this.$router.push({
          name: "wordBankCenter",
        });
        return;
      }
      this.$router.push({
        name: "studyCenter",
      });
    },
    processingData(res) {
      if (res.data && res.data.group_id) {
        this.tagGroupId = res.data.group_id;
      }
      if (
        res.code == 200 &&
        res.data &&
        res.data.word_pronunciation_vo_list &&
        res.data.word_pronunciation_vo_list.length > 0
      ) {
        if (
          this.groupData &&
          this.groupData.group_id &&
          this.groupData.group_id !== res.data.group_id
        ) {
          this.addIntegral(this.groupData.group_id);
          this.setInitWordNum();
        }
        // 结算学币
        res.data.word_pronunciation_vo_list.forEach((item) => {
          let paraphrase = [];
          item.word_paraphrase_vo_list.map((item2) => {
            paraphrase.push(
              (item2.word_sex ? item2.word_sex : "") + item2.paraphrase
            );
          });
          item.id = item.word_id; //ID
          // item.name = item.word_name; //单词
          // item.phonetic = item.phonetic; //音标
          item.imgURL =
            item.word_picture_vo_list.length > 0
              ? item.word_picture_vo_list[0].url
              : ""; //图片
          item.exampleList = item.word_example_vo_list; //例句
          item.audioURL = item.word_audio_vo_list[0]
            ? item.word_audio_vo_list[0].url
            : ""; //音频
          item.paraphrase = paraphrase; //释义
        });
        this.checkedWordIndex = -1;
        this.intensiveWordIndex = -1;
        this.groupData = res.data;
        let reviewData = res.data.word_pronunciation_vo_list.filter((word) => {
          return word.is_skip == 1 && word.is_finish == 0;
        });
        reviewData.forEach((item) => {
          item.isReview = true;
        });
        let studyData = res.data.word_pronunciation_vo_list.filter((word) => {
          // return word.is_skip == 0;
          return !word.is_skip;
        });
        let wordListData;
        if (this.$route.query.title == "体验生词库") {
          wordListData = [...studyData];
        } else {
          wordListData = [...reviewData, ...studyData];
        }

        if (wordListData.length > 0) {
          EventBus.$emit("closeLoading", {});
          this.isIintensiveWord = false;
          this.wordList = wordListData;
          this.nextWord();
        } else {
          let data;
          if (this.$route.query.title == "体验生词库") {
            this.intensiveWordList = res.data.word_pronunciation_vo_list.map(
              (item) => item
            );
            data = {
              book_id: this.checkedBookData.book_id,
              question_type: 1,
              source: 0,
              // unit_id_list: [this.unitId],
              grade_id: Number(this.unitId),
              word_id_list: this.intensiveWordList.map((item) => item.word_id),
            };
          } else if (this.$route.query.title == "单词库") {
            this.intensiveWordList = res.data.word_pronunciation_vo_list.map(
              (item) => item
            );
            data = {
              book_id: this.checkedBookData.book_id,
              question_type: 1,
              source: 0,
              // unit_id_list: [this.unitId],
              grade_id: Number(this.unitId),
              word_id_list: this.intensiveWordList.map((item) => item.word_id),
            };
          } else {
            if (this.testId == 1) {
              //是否跳过词义强化
              if (res.data.is_skip == 1) {
                //跳出弹窗
                this.isSkipIntensiveWord = true;
              } else if (res.data.is_skip == 2) {
                //强制跳过
                this.isSkipIntensiveWord = false;
                this.SkipIntensiveWord(1);
              } else {
                this.intensiveWordList = res.data.word_pronunciation_vo_list.filter(
                  (word) => {
                    word.checkedNum = 0;
                    word.wrongNum = 0;
                    return word.is_finish == 1 && word.correct_num < 1;
                  }
                );
                // 获取词义强化的题目
                let data = {
                  book_id: this.checkedBookData.book_id,
                  question_type: 1,
                  source: this.category,
                  unit_id_list: [this.unitId],
                  word_id_list: this.intensiveWordList.map(
                    (item) => item.word_id
                  ),
                };
                getWordQuestions(data)
                  .then((res) => {
                    this.wordRaising(res);
                  })
                  .catch(() => {
                    EventBus.$emit("closeLoading", {});
                  });
              }
              return;
            }
            this.intensiveWordList = res.data.word_pronunciation_vo_list.filter(
              (word) => {
                word.checkedNum = 0;
                word.wrongNum = 0;
                return word.is_finish == 1 && word.correct_num < 1;
              }
            );
            data = {
              book_id: this.checkedBookData.book_id,
              question_type: 1,
              source: this.category,
              unit_id_list: [this.unitId],
              word_id_list: this.intensiveWordList.map((item) => item.word_id),
            };
          }
          // 获取词义强化的题目
          if (this.$route.query.title == "体验生词库") {
            data.book_id = 600;
            data.source = 4;
            experienceCreate(data)
              .then((res) => {
                this.wordRaising(res);
              })
              .catch(() => {
                EventBus.$emit("closeLoading", {});
              });
          } else if (this.$route.query.title == "单词库") {
            createInvidualizedWord(data)
              .then((res) => {
                this.wordRaising(res);
              })
              .catch(() => {
                EventBus.$emit("closeLoading", {});
              });
          } else {
            getWordQuestions(data)
              .then((res) => {
                this.wordRaising(res);
              })
              .catch(() => {
                EventBus.$emit("closeLoading", {});
              });
          }
        }
      } else {
        EventBus.$emit("closeLoading", {});
        if (this.$route.query.title == "体验生词库") {
          this.$alert("体验生词已学习已完成,即将返回学习中心", "提示", {
            confirmButtonText: "确定",
          })
            .then(() => {
              this.$router.push({
                name: "experientialStudyCenter",
              });
            })
            .catch(() => {
              this.$router.push({
                name: "experientialStudyCenter",
              });
            });
          return;
        }
        if (this.$route.query.title == "单词库") {
          console.log(111111);
          this.$alert("录入单词已学习已完成,即将返回学习中心", "提示", {
            confirmButtonText: "确定",
          })
            .then(() => {
              this.$router.push({
                name: "wordBank",
              });
            })
            .catch(() => {
              this.$router.push({
                name: "wordBank",
              });
            });
          return;
        }
        if (this.groupData && this.groupData.group_id) {
          this.addIntegral(this.groupData.group_id);
        }
        if (!this.isOpenMessageBox) {
          this.isOpenMessageBox = true;
          this.$confirm("智能记忆学习已完成,前往极速挑战", "提示", {
            confirmButtonText: "极速模式",
            cancelButtonText: "普通模式",
            showClose: true,
            distinguishCancelAndClose: true,
            closeOnClickModal: false,
            closeOnPressEscape: false,
            beforeClose: (action, instance, done) => {
              this.$beforeConfirmClose(action, instance, done);
            },
          })
            .then(() => {
              this.isOpenMessageBox = false;
              this.$router.push({
                name: "quickTest",
                query: {
                  unitId: this.unitId,
                  category: this.category,
                },
              });
            })
            .catch((type) => {
              this.isOpenMessageBox = false;
              if (type != "close") {
                this.$router.push({
                  name: "generalTest",
                  query: {
                    unitId: this.unitId,
                    category: this.category,
                  },
                });
              } else {
                this.$router.push({
                  name: "studyCenter",
                });
              }
            });
        }
      }
    },
    wordRaising(res) {
      EventBus.$emit("closeLoading", {});
      if (res.code == 200 && res.data) {
        // console.log(333333444);
        // console.log(res,"test1");
        // console.log(this.intensiveWordList,"test2");

        this.intensiveWordList.forEach((item) => {
          let questionData = res.data.filter((question) => {
            return question.word_id == item.word_id;
          });
          if (questionData.length > 0) {
            let question = questionData[0];
            question.studentAnswer = "";
            question.isChecked = false;
            question.trueAnswer = "";
            question.audioURL = item.audioURL;
            let answerData = question.answer_list.filter((item) => {
              if (item.is_true && item.is_true == 1) {
                return true;
              } else {
                return false;
              }
            });
            if (answerData.length > 0) {
              question.trueAnswer = answerData[0].paraphrase;
            }
            item.question = Object.assign({}, question);
            item.num = 0;
          }
        });
        if (this.$route.query.title == "单词库") {
          this.intensiveWordList = this.intensiveWordList.filter(
            (item) => item.question
          );
        }
        // console.log(this.intensiveWordList,"this.intensiveWordList");
        this.isIintensiveWord = true;
        this.nextIntensiveWord();
      }
    },
    // 查询单词
    getStudyWordList() {
      let params;
      if (this.$route.query.title == "体验生词库") {
        params = {
          unitId: this.unitId,
          phoneticCategory: this.$store.getters.isBritish,
          bookId: 600,
          number: this.checkedBookData.number,
          source: this.category,
        };
        EventBus.$emit("openLoading", {});
        experiencefindWordPronunciationVo(params)
          .then((res) => {
            this.processingData(res);
          })
          .catch(() => {
            EventBus.$emit("closeLoading", {});
          });
      } else if (this.$route.query.title == "单词库") {
        this.tagGroupId = this.tagGroupId ? this.tagGroupId + 1 : 0;
        params = {
          gradeId: this.$route.query.unitId,
          // individual/findWordPronunciationVo
          groupId: this.$route.query.groupId,
          phoneticCategory: this.$store.getters.isBritish,
          bookId: this.checkedBookData.book_id,
          number: this.tagGroupId,
          source: 0,
        };
        EventBus.$emit("openLoading", {});
        findWordPronunciationVo(params)
          .then((res) => {
            this.processingData(res);
          })
          .catch(() => {
            EventBus.$emit("closeLoading", {});
          });
      } else {
        params = {
          unitId: this.unitId,
          phoneticCategory: this.$store.getters.isBritish,
          bookId: this.checkedBookData.book_id,
          number: this.checkedBookData.number,
          source: this.category,
          classId: JSON.parse(localStorage.getItem("bookData")).id,
        };
        EventBus.$emit("openLoading", {});
        getStudyWordList(params)
          .then((res) => {
            this.processingData(res);
          })
          .catch(() => {
            EventBus.$emit("closeLoading", {});
          });
      }
    },
    setCountTimer() {
      this.countTimerNum = 5;
      if (this.countTimer) {
        clearInterval(this.countTimer);
      }
      this.countTimer = setInterval(() => {
        this.countTimerNum--;
        if (this.countTimerNum <= 0) {
          clearInterval(this.countTimer);
          this.$refs.studyWord.checkFalseFun();
        }
      }, 1000);
    },
    // 获取复习的单词
    getMemoryReview() {
      if (this.$route.query.title == "体验生词库") {
        this.experienceWordReviewSearch();
        return;
      }
      if (this.$route.query.title == "单词库") {
        this.wordSearch();
        return;
      }
      console.log("test智能复习");
      let data = {
        page_require: {
          page_num: 1,
          page_size: 10,
        },
        category: this.category,
        book_id: this.checkedBookData.book_id,
      };
      getMemoryReview(data).then(async (res) => {
        if (res.code == 200 && res.data) {
          res.data.word_info_list.forEach((item) => {
            item.id = item.word_id; //ID
            item.name = item.word_name; //单词
            item.imgURL = ""; //图片
            item.exampleList = []; //例句
            item.phonetic =
              this.$store.getters.isBritish == 1
                ? item.phonetic_british
                : item.phonetic_american; //音标
            item.audioURL =
              this.$store.getters.isBritish == 1 ? item.en_url : item.us_url; //音频
            item.paraphrase = item.paraphrase.split("\n"); //释义
          });
          let data = res.data.word_info_list.filter((item) => {
            item.checkedNum = 0;
            item.wrongNum = 0;
            return item.time_interval <= 0;
          });
          if (data.length > 0) {
            this.isIintensiveWord = true;
            this.intensiveWordIndex = -1;
            this.intensiveWordList = data;
            // 获取词义强化的题目
            let postData = {
              book_id: this.checkedBookData.book_id,
              question_type: 1,
              source: this.category,
              unit_id_list: this.unitId ? [this.unitId] : null,
              word_id_list: data.map((item) => item.word_id),
            };
            getWordQuestions(postData).then((res) => {
              if (res.code == 200 && res.data) {
                this.intensiveWordList.forEach((item) => {
                  let questionData = res.data.filter((question) => {
                    return question.word_id == item.word_id;
                  });
                  if (questionData.length > 0) {
                    let question = questionData[0];
                    question.studentAnswer = "";
                    question.isChecked = false;
                    question.trueAnswer = "";
                    question.audioURL = item.audioURL;
                    let answerData = question.answer_list.filter((item) => {
                      if (item.is_true && item.is_true == 1) {
                        return true;
                      } else {
                        return false;
                      }
                    });
                    if (answerData.length > 0) {
                      question.trueAnswer = answerData[0].paraphrase;
                    }
                    item.question = Object.assign({}, question);
                  }
                });
                this.isIintensiveWord = true;
                this.nextIntensiveWord();
              }
            });
          } else {
            // 记忆复习完了
            this.cancelForce();
            if (!this.isOpenMessageBox) {
              this.isOpenMessageBox = true;
              let nextData = await this.getReviewNumber();
              if (nextData) {
                this.$confirm(
                  `智能${
                    this.$store.getters.wordCategory[this.category].title
                  }已复习完成，是否前往智能${
                    this.$store.getters.wordCategory[nextData.category].title
                  }复习`,
                  "提示",
                  {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnClickModal: false,
                    closeOnPressEscape: false,
                  }
                )
                  .then(() => {
                    this.isOpenMessageBox = false;
                    this.$router.push({
                      name: this.$store.getters.wordCategory[nextData.category]
                        .route,
                      query: { ...this.$route.query },
                    });
                  })
                  .catch(() => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                    return false;
                  });
              } else {
                this.$alert("智能记忆已复习完成", "消息提示", {
                  confirmButtonText: "确定",
                  callback: () => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                  },
                });
                // this.$confirm(`智能记忆已复习完成`, "提示", {
                //   confirmButtonText: "返回学习中心",
                //   cancelButtonText: "取消",
                //   closeOnClickModal: false,
                //   closeOnPressEscape: false,
                // })
                //   .then(() => {
                //     this.isOpenMessageBox = false;
                //     this.goStudyCenter();
                //   })
                //   .catch(() => {
                //     this.isOpenMessageBox = false;
                //     return false;
                //   });
              }
            }
          }
        }
      });
    },
    experienceWordReviewSearch() {
      let data = {
        book_id: 600,
        category: 0,
        unit_id: this.$route.query.unitId,
        page_require: { page_num: 1, page_size: 10 },
      };
      experienceWordReviewSearch(data).then(async (res) => {
        if (res.code == 200 && res.data) {
          res.data.word_info_list.forEach((item) => {
            item.id = item.word_id; //ID
            item.name = item.word_name; //单词
            item.imgURL = ""; //图片
            item.exampleList = []; //例句
            item.phonetic =
              this.$store.getters.isBritish == 1
                ? item.phonetic_british
                : item.phonetic_american; //音标
            item.audioURL =
              this.$store.getters.isBritish == 1 ? item.en_url : item.us_url; //音频
            item.paraphrase = item.paraphrase.split("\n"); //释义
          });
          let data = res.data.word_info_list.map((item) => {
            item.checkedNum = 0;
            item.wrongNum = 0;
            return item;
          });
          if (data.length > 0) {
            this.isIintensiveWord = true;
            this.intensiveWordIndex = -1;
            this.intensiveWordList = data;
            // 获取词义强化的题目
            let postData = {
              type: 1,
              book_id: 600,
              question_type: 1,
              source: 0,
              grade_id: Number(this.unitId),
              unit_id_list: this.unitId ? [this.unitId] : null,
              word_id_list: data.map((item) => item.word_id),
            };
            experienceCreate(postData).then((res) => {
              console.log(1111111);
              if (res.code == 200 && res.data) {
                this.intensiveWordList.forEach((item) => {
                  let questionData = res.data.filter((question) => {
                    return question.word_id == item.word_id;
                  });
                  if (questionData.length > 0) {
                    let question = questionData[0];
                    question.studentAnswer = "";
                    question.isChecked = false;
                    question.trueAnswer = "";
                    question.audioURL = item.audioURL;
                    let answerData = question.answer_list.filter((item) => {
                      if (item.is_true && item.is_true == 1) {
                        return true;
                      } else {
                        return false;
                      }
                    });
                    if (answerData.length > 0) {
                      question.trueAnswer = answerData[0].paraphrase;
                    }
                    item.question = Object.assign({}, question);
                  }
                });
                this.isIintensiveWord = true;
                this.nextIntensiveWord();
              }
            });
          } else {
            // 记忆复习完了
            this.cancelForce();
            if (!this.isOpenMessageBox) {
              this.isOpenMessageBox = true;
              let nextData = await this.getReviewNumber();
              if (nextData) {
                this.$confirm(
                  `智能${
                    this.$store.getters.wordCategory[this.category].title
                  }已复习完成，是否前往智能${
                    this.$store.getters.wordCategory[nextData.category].title
                  }复习`,
                  "提示",
                  {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnClickModal: false,
                    closeOnPressEscape: false,
                  }
                )
                  .then(() => {
                    this.isOpenMessageBox = false;
                    this.$router.push({
                      name: this.$store.getters.wordCategory[nextData.category]
                        .route,
                      query: {
                        isReview: true,
                      },
                    });
                  })
                  .catch(() => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                    return false;
                  });
              } else {
                this.$alert("智能记忆已复习完成", "消息提示", {
                  confirmButtonText: "确定",
                  callback: () => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                  },
                });
                // this.$confirm(`智能记忆已复习完成`, "提示", {
                //   confirmButtonText: "返回学习中心",
                //   cancelButtonText: "取消",
                //   closeOnClickModal: false,
                //   closeOnPressEscape: false,
                // })
                //   .then(() => {
                //     this.isOpenMessageBox = false;
                //     this.goStudyCenter();
                //   })
                //   .catch(() => {
                //     this.isOpenMessageBox = false;
                //     return false;
                //   });
              }
            }
          }
        }
      });
    },
    wordSearch() {
      let data = {
        book_id: this.checkedBookData.book_id,
        category: 0,
        grade_id: this.$route.query.unitId,
        page_require: { page_num: 1, page_size: 10 },
      };
      wordSearch(data).then(async (res) => {
        if (res.code == 200 && res.data) {
          res.data.word_info_list.forEach((item) => {
            item.id = item.word_id; //ID
            item.name = item.word_name; //单词
            item.imgURL = ""; //图片
            item.exampleList = []; //例句
            item.phonetic =
              this.$store.getters.isBritish == 1
                ? item.phonetic_british
                : item.phonetic_american; //音标
            item.audioURL =
              this.$store.getters.isBritish == 1 ? item.en_url : item.us_url; //音频
            item.paraphrase = item.paraphrase.split("\n"); //释义
          });
          let data = res.data.word_info_list.map((item) => {
            item.checkedNum = 0;
            item.wrongNum = 0;
            return item;
          });
          if (data.length > 0) {
            this.isIintensiveWord = true;
            this.intensiveWordIndex = -1;
            this.intensiveWordList = data;
            // 获取词义强化的题目
            let postData = {
              type: 1,
              book_id: this.checkedBookData.book_id,
              question_type: 1,
              source: 0,
              grade_id: Number(this.unitId),
              unit_id_list: this.unitId ? [this.unitId] : null,
              word_id_list: data.map((item) => item.lid),
            };
            createInvidualizedWord(postData).then((res) => {
              console.log(1111111);
              if (res.code == 200 && res.data) {
                this.intensiveWordList.forEach((item) => {
                  let questionData = res.data.filter((question) => {
                    return question.word_id == item.word_id;
                  });
                  if (questionData.length > 0) {
                    let question = questionData[0];
                    question.studentAnswer = "";
                    question.isChecked = false;
                    question.trueAnswer = "";
                    question.audioURL = item.audioURL;
                    let answerData = question.answer_list.filter((item) => {
                      if (item.is_true && item.is_true == 1) {
                        return true;
                      } else {
                        return false;
                      }
                    });
                    if (answerData.length > 0) {
                      question.trueAnswer = answerData[0].paraphrase;
                    }
                    item.question = Object.assign({}, question);
                  }
                });
                this.isIintensiveWord = true;
                this.nextIntensiveWord();
              }
            });
          } else {
            // 记忆复习完了
            this.cancelForce();
            if (!this.isOpenMessageBox) {
              this.isOpenMessageBox = true;
              let nextData = await this.getReviewNumber();
              if (nextData) {
                this.$confirm(
                  `智能${
                    this.$store.getters.wordCategory[this.category].title
                  }已复习完成，是否前往智能${
                    this.$store.getters.wordCategory[nextData.category].title
                  }复习`,
                  "提示",
                  {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnClickModal: false,
                    closeOnPressEscape: false,
                  }
                )
                  .then(() => {
                    this.isOpenMessageBox = false;
                    this.$router.push({
                      name: this.$store.getters.wordCategory[nextData.category]
                        .route,
                      query: {
                        isReview: true,
                      },
                    });
                  })
                  .catch(() => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                    return false;
                  });
              } else {
                this.$alert("智能记忆已复习完成", "消息提示", {
                  confirmButtonText: "确定",
                  callback: () => {
                    this.isOpenMessageBox = false;
                    this.goStudyCenter();
                  },
                });
                // this.$confirm(`智能记忆已复习完成`, "提示", {
                //   confirmButtonText: "返回学习中心",
                //   cancelButtonText: "取消",
                //   closeOnClickModal: false,
                //   closeOnPressEscape: false,
                // })
                //   .then(() => {
                //     this.isOpenMessageBox = false;
                //     this.goStudyCenter();
                //   })
                //   .catch(() => {
                //     this.isOpenMessageBox = false;
                //     return false;
                //   });
              }
            }
          }
        }
      });
    },
    getReviewNumber() {
      return new Promise((reslove) => {
        getReviewNumber(this.checkedBookData.book_id)
          .then((res) => {
            if (res.code == 200 && res.data) {
              console.log(res);
              let data = res.data.filter((item) => {
                return item.category > this.category && item.num > 0;
              });
              if (data.length > 0) {
                reslove(data[0]);
              }
            }
            reslove(null);
          })
          .catch(() => {
            reslove(null);
          });
      });
    },
    getStudyData() {
      if (this.isReview) {
        this.getMemoryReview();
      } else {
        this.getStudyWordList();
      }
    },
    closeTimer() {
      clearInterval(this.countTimer);
    },
    addIntegral(groupId) {
      let params = {
        groupId,
        source: this.category,
        bookId: this.checkedBookData.book_id,
        unitId: this.unitId,
        type: 1,
      };
      addIntegral(params).then((res) => {
        if (res.code == 200) {
          this.addIntegralNum += res.data;
        }
      });
    },
    watchKeyDown(e) {
      if (this.isOpenMessageBox) {
        return;
      }
      if (this.isIintensiveWord) {
        if (e.keyCode == 13) {
          this.nextIntQuestion();
        }
        if (!this.intensiveWord.question.isChecked) {
          if (e.keyCode == 49 || e.keyCode == 97) {
            this.checkAnswer(1);
          }
          if (e.keyCode == 50 || e.keyCode == 98) {
            this.checkAnswer(2);
          }
          if (e.keyCode == 51 || e.keyCode == 99) {
            this.checkAnswer(3);
          }
          if (e.keyCode == 52 || e.keyCode == 100) {
            this.checkAnswer(4);
          }
        }
      }
      //97-100
    },
    // 1/2/3/4选择选项
    checkAnswer(num) {
      if (
        this.intensiveWord.question.answer_list &&
        this.intensiveWord.question.answer_list[num - 1]
      ) {
        let answer = this.intensiveWord.question.answer_list[num - 1];
        if (this.$refs[`testQuestion`]) {
          this.$refs[`testQuestion`].studentAnswer =
            answer.word_id || answer.word_name || answer.paraphrase;
          this.$refs[`testQuestion`].changeStudentAnswer();
        }
      }
    },
  },
  created() {
    this.checkedBookData = JSON.parse(localStorage.getItem("bookData"));
    let data = this.checkedBookData.word_book_vo_list.filter((item) => {
      return item.source == this.category;
    });
    if (data.length > 0) {
      this.checkedBookData.number = data[0].number;
    } else {
      this.checkedBookData.number = 1;
    }
    this.unitId = this.$route.query.unitId;
    this.isReview = !!this.$route.query.isReview;
    this.isForce = Number(this.$route.query.isForce);
    this.getStudyData();
  },
  mounted() {
    window.addEventListener("keydown", this.watchKeyDown);
  },
  beforeDestroy() {
    this.closeTimer();
    window.removeEventListener("keydown", this.watchKeyDown);
  },
};
</script>
<style lang="scss" scoped>
.historyWordList {
  /deep/.el-tag--warning {
    margin: 5px;
  }
}
</style>
